    {include file="../application/admin/view/common/header.html" /}
        
        <!--main content start-->
        <section class="main-content">


            <!--start page content-->

            <div class="row">
               
                 <div class="col-md-12">
                    <div class="panel panel-default collapsed">
                        <div class="panel-heading"> 
                            <a class="btn btn-danger ui-w" onclick="datadel()" href="javascript:void(0);"><span class="ui-icon ui-icon-trash"> </span>批量删除</a>
                            <a class="btn btn-blue ui-w" onclick="start_backup(this)" href="javascript:void(0);">备份数据库</a>
                            <div class="float-m" style="display: inline-block;">
                                <label>日期范围:</label>
                                <input type="text" id="logmin" class="input-text Wdate" style="width:100px;display: inline-block;">
                                -
                                <input type="text" id="logmax" class="input-text Wdate" style="width:100px;display: inline-block;">
                            </div>
                            <div class="search-form" style="margin-left:10px;width: 200px; ">
                                <input type="text" class="form-control" style="width: 200px;" placeholder="输入文件名" />
                                <button type="button" class="btn-search"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                        <div class="panel-body">
                            
                            <table class="table table-hover table-striped table-bordered" data-page-size="12" data-filter=#filter>
                                <thead>
                                <tr>
                                    <th>选择</th>
                                    <th>序号</th>
                                    <th>文件名</th>
                                    <th>文件大小</th>
                                    <th>备份时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td><input type="checkbox" name=""></td>
                                        <td>01</td>
                                        <td>20180112.sql</td>
                                        <td>3MB</td>
                                        <td>2017-12-12 12:12:12</td>
                                        <td class="buttons td-manage">
                                            <a class="btn table-btn " onclick="database_backup(this)" href="javascript:;" title="回滚数据库"><i class="fa fa-reply"></i></a>
                                            <a class="btn table-btn" onclick="database_del(this,'1')" href="#" title="删除"><i class="fa fa-trash-o"></i></a>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td><input type="checkbox" name=""></td>
                                        <td>01</td>
                                        <td>20180112.sql</td>
                                        <td>3MB</td>
                                        <td>2017-12-12 12:12:12</td>
                                        <td class="buttons td-manage">
                                            <a class="btn table-btn " onclick="database_backup(this)" href="javascript:;" title="回滚数据库"><i class="fa fa-reply"></i></a>
                                            <a class="btn table-btn" onclick="database_del(this,'1')" href="#" title="删除"><i class="fa fa-trash-o"></i></a>
                                        </td>
                                    </tr>

                                    
                                
                                </tbody>
                            </table>
                            <div class="pager" id="page" style="text-align: right;"></div>
                         </div>
                    </div>
                </div>
            </div><!--end row-->
            
            <!--end page content-->



            <!-- <footer class="footer">
                <span></span>
            </footer> -->
       

        </section>
        <!--end main content-->



        <!--Common plugins-->
        <script src="_JS_/jquery.min.js"></script>
        <script src="_JS_/bootstrap.min.js"></script>
        <script src="_JS_/jasny-bootstrap.min.js"></script>
        <script src="_JS_/jquery.slimscroll.min.js"></script>
        <script src="_JS_/jquery.nanoscroller.min.js"></script>
        <script src="_JS_/metismenu.min.js"></script>
        <script src="_JS_/float-custom.js"></script>
        <script type="text/javascript" src="_JS_/layer/layer.js"></script>
        <script type="text/javascript" src="_JS_/laypage/laypage.js"></script> 
        <script type="text/javascript" src="_JS_/laydata/laydate.js"></script> 
        <!-- <script src="_JS_/footable.all.min.js"></script> -->
         <!-- Page-Level Scripts -->
    <script>
     /*分页*/
     laypage({
        cont: 'page',
        pages: 10,
        jump: function(obj){
            /*跳转*/        
        }
    })
     /*批量删除*/
     function datadel(){
        layer.confirm('确认要删除多个吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
     }



    function  formatDate(time){
        if(time){
            var  now = new Date(time*1000);
        }else{
           var  now = new Date(); 
        }
        var  year=now.getFullYear();
        var  month = "0"+(now.getMonth()+1);
        var  month=now.getMonth()+1<10?"0"+(now.getMonth()+1):now.getMonth()+1;     
        var  date=now.getDate()<10?"0"+now.getDate():now.getDate();     
        var  hour=now.getHours()<10?"0"+now.getHours():now.getHours();     
        var  minute=now.getMinutes()<10?"0"+now.getMinutes():now.getMinutes();     
        var  second=now.getSeconds()<10?"0"+now.getSeconds():now.getSeconds();
        return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;    
    }
    
     //备份
    function start_backup(obj){
        layer.confirm('您是否确定要备份数据库？', {
            btn: ['备份','取消'] //按钮
        }, function(){
            var length = 0;
            var progress = "";
            var currentIndex = 0;
            var status = 1;
            $.ajax({
                type:"post",
                url:"{:url('api/Mysql/dataList')}",
                jsonp:"callback",
                dataType:"jsonp",
                success:function(msg){
                    var index=layer.confirm();
                    layer.close(index);
                    if(msg){
                        var url = formatDate();
                        layer.open({
                            type: 1,
                            title:'备份进度',
                            closeBtn:0,
                            area: ['420px', '100px'], //宽高
                            content: '<div style="width:300px;height:30px;border:1px solid #dde6e9;margin-left:60px;margin-top:10px;"><span id="scoll" style="display:block;height:30px;width:0%;background-color:#5eb95e;"></span></div>'
                        });
                        datastart(msg.info,url,msg.count);
                    }else{
                        layer.msg("备份失败");
                        return false;
                    }   
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    layer.msg("备份失败");
                    return false;        
                }
            });

            function datastart(obj,url,count){
                if(currentIndex>=obj.length){  
                    return false; 
                }
                if(status == 0){
                    layer.closeAll();//备份完成时关闭 
                    layer.msg("备份失败");
                    return false;
                }
                $.ajax({
                    type:"post",
                    url:"{:url('api/Mysql/start')}",
                    async:true,
                    data:{
                        "name":obj[currentIndex].name,
                        "url":url,
                        "_count":obj[currentIndex].data_length
                    },
                    jsonp:"callback",
                    dataType:"jsonp",
                    success:function(msg){
                        if(msg == "success"){
                            length += obj[currentIndex].data_length
                            progress = (length/count)*100+"%";
                            $("#scoll").css("width",progress);
                            if(length/count >= 1){
                                status = 2;
                                layer.closeAll();//备份完成时关闭 
                                dataAdd(url,count);
                                return false;
                            }
                        }else{
                            status = 0;
                        }
                        currentIndex++;
                        datastart(obj,url,count);
                        return false;
                    },
                    error:function(){
                        layer.msg("备份失败");
                        layer.closeAll();//备份完成时关闭 
                        return false;
                    }
                });
            }

            function dataAdd(url,count){
                $.ajax({
                    type:"post",
                    url:"{:url('api/Mysql/dataAdd')}",
                    async:true,
                    data:{
                        "url":url,
                        "count":count,
                    },
                    jsonp:"callback",
                    dataType:"jsonp",
                    success:function(msg){
                        if(msg == "success"){
                            layer.msg("备份成功");
                            return false;
                        }else{
                            layer.msg("备份失败");
                            return false;
                        }
                    }
                });
            }
        }, function(){
          layer.closeAll();
        });
        
    }
    /*回滚*/
    function database_backup(obj){
        layer.confirm('您是否确定要备份数据库？', {
            btn: ['备份','取消'] //按钮
        }, function(){
            var currentIndex = 0;
            var status = 1;
            var filename = 1;
            var count = 167012;
            $.ajax({
                type:"post",
                url:"{:url('api/Mysql/backup_list')}",
                jsonp:"callback",
                dataType:"jsonp",
                data:{
                    "filename":filename,
                },
                success:function(msg){
                    var index=layer.confirm();
                    layer.close(index);
                    if(msg.status == "success"){
                        layer.open({
                            type: 1,
                            title:'回滚进度',
                            closeBtn:0,
                            area: ['420px', '100px'], //宽高
                            content: '<div style="width:300px;height:30px;border:1px solid #dde6e9;margin-left:60px;margin-top:10px;"><span id="scoll1" style="display:block;height:30px;width:0%;background-color:#5eb95e;"></span></div>'
                        });
                        revstart(msg.info);
                    }else{
                        layer.msg("还原失败");
                        return false;  
                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    layer.msg("还原失败");
                    return false;        
                }
            });

            function revstart(obj){
                if(currentIndex>=obj.info.length){  
                    return false; 
                }
                if(status == 0){
                    layer.closeAll();//备份完成时关闭 
                    layer.msg("备份失败");
                    return false;
                }
                $.ajax({
                    type:"post",
                    url:"{:url('api/Mysql/rev')}",
                    async:true,
                    data:{
                        'file_name':obj.info[currentIndex].part,
                        'filename':filename
                    },
                    jsonp:"callback",
                    dataType:"jsonp",
                    success:function(msg){
                        if(msg.status == "success"){
                            length += msg.info.size;
                            progress = (length/count)*100+"%";
                            $("#scoll1").css("width",progress);
                            if(length/count >= 1){
                                status = 2;
                                layer.closeAll();//备份完成时关闭 
                                log_add();
                                return false;
                            }
                        }else{
                            status = 0;
                        }
                        currentIndex++;
                        revstart(obj);
                        return false;
                    },
                    error:function(){
                        layer.msg("备份失败");
                        layer.closeAll();//备份完成时关闭 
                        return false;
                    }
                });
            }

            function log_add(){
                if(status == 2){
                    layer.msg("备份成功");
                }else{
                    layer.msg("备份失败");
                }
            }
        }, function(){
          layer.closeAll();
        });
    }

    /*删除*/
    function database_del(obj){
        layer.confirm('确认要删除吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }

   //日期范围限制
    var start = {
        elem: '#logmin',
        format: 'YYYY-MM-DD',
        min: '1970-01-01', //设定最小日期为当前日期
        max: laydate.now(), //最大日期
        istime: false,
        istoday: false,
        choose: function(datas){
             end.min = datas; //开始日选好后，重置结束日的最小日期
             end.start = datas //将结束日的初始值设定为开始日
        }
    };

    var end = {
        elem: '#logmax',
        format: 'YYYY-MM-DD',
        min: '1970-01-01',
        max: laydate.now(),
        istime: false,
        istoday: false,
        choose: function(datas){
            start.max = datas; //结束日选好后，充值开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);



    </script>
    </body>
</html>